﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Unity.Configuration;
using MyBlog.Service;
using MyBlog.ServiceInterface;
using MyBlog.DataAccessInterface;
using MyBlog.DataAccess;
using MyBlog.BusinessInterface;
using MyBlog.Business;

namespace MyBlog.Unity
{
    public class UnityConfig
    {
        static IUnityContainer _container;
        static UnityConfig()
        {
            _container = new UnityContainer();
        }
        public static void RegisterAllService()
        {
            //UnityConfigurationSection configuration = (UnityConfigurationSection)ConfigurationManager.GetSection(UnityConfigurationSection.SectionName);
            //configuration.Configure(_container, "defaultContainer");
            //_container.RegisterType<IControllerActivator, CustomControllerActivator>();
            //DependencyResolver.SetResolver(new UnityDependencyResolver(_container));
            _container.RegisterType<IUnitOfWork, BlogContext>();
            _container.RegisterType<IContext, BlogContext>();

            _container.RegisterType<IDALAccount, AccountContext>();
            _container.RegisterType<IBusinessAccount, BusinessAccount>();
            _container.RegisterType<IAccountService, AccountService>();

            _container.RegisterType<IDALAlbum, AlbumContext>();
            _container.RegisterType<IBusinessAlbum, BusinessAlbum>();
            _container.RegisterType<IAlbumService, AlbumService>();

            _container.RegisterType<IDALAlbumDetail, AlbumDetailContext>();
            _container.RegisterType<IBusinessAlbumDetail, BusinessAlbumDetail>();

            _container.RegisterType<IDALArticle, ArticleContext>();
            _container.RegisterType<IBusinessArticle, BusinessArticle>();
            _container.RegisterType<IArticleService, ArticleService>();

            _container.RegisterType<IDALArticleComment, ArticleCommentContext>();
            _container.RegisterType<IBusinessArticleComment, BusinessArticleComment>();
            _container.RegisterType<IArticleCommentService, ArticleCommentService>();

            _container.RegisterType<IDALBug, BugContext>();
            _container.RegisterType<IBusinessBug, BusinessBug>();
            _container.RegisterType<IBugService, BugService>();

            _container.RegisterType<IDALCategory, CategoryContext>();
            _container.RegisterType<IBusinessCategory, BusinessCategory>();
            _container.RegisterType<ICategoryService, CategoryService>();

            _container.RegisterType<IDALTag, TagContext>();
            _container.RegisterType<IBusinessTag, BusinessTag>();
            _container.RegisterType<ITagService, TagService>();

            _container.RegisterType<IDALConcern, ConcernContext>();
            _container.RegisterType<IBusinessConcern, BusinessConcern>();
            _container.RegisterType<IConcernService, ConcernService>();

            _container.RegisterType<IDALNotice, NoticeContext>();
            _container.RegisterType<IBusinessNotice, BusinessNotice>();
            _container.RegisterType<INoticeService, NoticeService>();

            _container.RegisterType<IDALHeader, HeaderContext>();
            _container.RegisterType<IBusinessHeader, BusinessHeader>();

            _container.RegisterType<IDALMessage, MessageContext>();
            _container.RegisterType<IBusinessMessage, BusinessMessage>();
            _container.RegisterType<IMessageService, MessageService>();

            _container.RegisterType<IDALMood, MoodContext>();
            _container.RegisterType<IBusinessMood, BusinessMood>();
            _container.RegisterType<IMoodService, MoodService>();

            _container.RegisterType<IDALMoodComment, MoodCommentContext>();
            _container.RegisterType<IBusinessMoodComment, BusinessMoodComment>();
            _container.RegisterType<IMoodCommentService, MoodCommentService>();

            _container.RegisterType<IDALMsgReply, MsgReplyContext>();
            _container.RegisterType<IBusinessMsgReply, BusinessMsgReply>();
            _container.RegisterType<IMsgReplyService, MsgReplyService>();

            _container.RegisterType<IDALPicComment, PicCommentContext>();
            _container.RegisterType<IBusinessPicComment, BusinessPicComment>();

            _container.RegisterType<IDALSysLog, SysLogContext>();
            _container.RegisterType<IBusinessSysLog, BusinessSysLog>();
            _container.RegisterType<ISysLogService, SysLogService>();

            _container.RegisterType<IDALVisitor, VisitorContext>();
            _container.RegisterType<IBusinessVisitor, BusinessVisitor>();
            _container.RegisterType<IVisitorService, VisitorService>();

            _container.RegisterType<IDALSysHistory, SysHistoryContext>();
            _container.RegisterType<IBusinessSysHistory, BusinessSysHistory>();
            _container.RegisterType<ISysHistoryService, SysHistoryService>();

            _container.RegisterType<IDALWords, WordsContext>();
            _container.RegisterType<IBusinessWords, BusinessWords>();
            _container.RegisterType<IWordsService, WordsService>();

            _container.RegisterType<IDALWordComment, WordCommentContext>();
            _container.RegisterType<IBusinessWordComment, BusinessWordComment>();
            _container.RegisterType<IWordCommentService, WordCommentService>();

            _container.RegisterType<IDALSysInfo, SysInfoContext>();
            _container.RegisterType<IBusinessSysInfo, BusinessSysInfo>();
            _container.RegisterType<ISysInfoService, SysInfoService>();
        }

        public static T GetService<T>()
        {
            return _container.Resolve<T>();
        }
    }
}